<?php
	include_once('../sys/sys.php');
	include_once('./gfun.php');
	include_once('./funcs.php');
	header('Content-Type: text/html; charset=utf-8');
	
	$action = $_GET['action'];
	//$accc = array();
	
	if ($action == 'elsesky'){
		//获取所有在下载中没连接的应用ID
		$row = $DB->build_query(array(
				'select' 	=> 'id,name',
				'from'		=> 'gfunapps',
// 				'where'		=>	"supportedos='null'",
		));
		$qid = $DB->exec_query();
		while ($row = $DB->fetch_row($qid)) {
			$appid = $row['id'];
			$where = 'AND appid= ' . $appid .'';
			$result = $DB->build_and_exec_query(
					array('select' => 'COUNT(*) as max','from'   => 'gfunappds','where'	=> "1 " . $where ,)
			);
			//当已经存在的时候更新图片链接
			if ($result['max'] > 0) {
				$content = file_get_contents(make_app_url($gfun_app_pre, $appid));
				//图片链接
				$i_url = explode('<ul class="clearfix" id="shot0106">', $content);
				$i_url = explode('</ul>',$i_url[1]);
				$match_str = '/src=\"(.*)\" class/isU';
				preg_match_all($match_str,$i_url[0],$i_urln);
				$i_url = $i_urln[1];
				unset($i_urln);
				unset($content);
				$DB->simple_delete('gfunpics' , ' appid= ' . $appid .'');
				$DB->query($DB->cur_query);
				$DB->cur_query = '';
				foreach ($i_url as $v) {
					if ($v == 'Images/default_icon.png'){
						$v = 'http://apk.gfan.com/Images/default_icon.png';
					}
					$DB->do_insert('gfunpics', array(
							'appid'					=> $appid,
							'imgorgurl'				=> $v,
							'imgurl'				=> basename($v),
					)
					);
				}
				
				
			}
			echo '应用<B><font color="red">'  . $row['name'] . "</font></B>重采集完毕<BR>";
			ob_flush();
		}
	}
	//print_r($accc);
	exit;
	
	
	
	
?>